package com.nuoniu.sibanyun.controller.finance;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.AccountingAuxiliaryLedgerDto;
import com.nuoniu.sibanyun.entity.finance.VAccountingAuxiliaryLedger;
import com.nuoniu.sibanyun.entity.finance.VAccountingSearchProgramme;
import com.nuoniu.sibanyun.service.finance.IVAccountingAuxiliaryLedgerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 辅助总账表 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-04-25
 */
@RestController
@RequestMapping("/finance/accountingAuxiliaryLedger")
@Api(tags = "辅助总账管理")
public class VAccountingAuxiliaryLedgerController extends BaseController {

    @Autowired
    private IVAccountingAuxiliaryLedgerService auxiliaryLedgerService;

    @ApiOperation("保存辅助科目期初")
    @PostMapping("save")
    public HttpResult save(@RequestBody List<VAccountingAuxiliaryLedger> auxiliaryLedger) {
        return HttpResult.ok(auxiliaryLedgerService.saveLedger(auxiliaryLedger));
    }

    @ApiOperation("获取辅助科目期初列表")
    @GetMapping("pageAuxiliaryBeginList")
    public HttpResult pageAuxiliaryBeginList(Page page, VAccountingSearchProgramme searchProgramme) {
        return HttpResult.ok(auxiliaryLedgerService.pageAuxiliaryBeginList(page, searchProgramme));
    }

    @ApiOperation("获取科目期初")
    @GetMapping("getAccountingBegin")
    public HttpResult getAccountingBegin(Integer accountingId) {
        return HttpResult.ok(auxiliaryLedgerService.getAccountingBegin(accountingId));
    }

    @ApiOperation("获取科目辅助余额")
    @GetMapping("pageAccountingAuxiliaryLedger")
    public HttpResult pageAccountingAuxiliaryLedger(Page page, VAccountingSearchProgramme searchProgramme) {
        Integer type = searchProgramme.getAuxiliaryType();
        if(type.equals(1)) {
            return HttpResult.ok(auxiliaryLedgerService.pageCrmAccountingAuxiliaryLedger(page, searchProgramme));
        } else if(type.equals(2)) {
            return HttpResult.ok(auxiliaryLedgerService.pageVendorAccountingAuxiliaryLedger(page, searchProgramme));
        } else if(type.equals(3)) {
            return HttpResult.ok(auxiliaryLedgerService.pageUserAccountingAuxiliaryLedger(page, searchProgramme));
        } else if(type.equals(4)) {
            return HttpResult.ok(auxiliaryLedgerService.pageOfficeAccountingAuxiliaryLedger(page, searchProgramme));
        } else {
            return HttpResult.ok(auxiliaryLedgerService.pageProjectAccountingAuxiliaryLedger(page, searchProgramme));
        }
    }

    @ApiOperation("获取辅助科目余额明细")
    @GetMapping("pageAccountingAuxiliaryLedgerList")
    public HttpResult<VAccountingAuxiliaryLedger> pageAccountingAuxiliaryLedgerList(Page page, VAccountingSearchProgramme searchProgramme) {
        return HttpResult.ok(auxiliaryLedgerService.pageAccountingAuxiliaryLedgerList(page, searchProgramme));
    }

    @ApiOperation("辅助总账/明细账")
    @GetMapping("pageAccountingAuxiliaryDetailList")
    public HttpResult<AccountingAuxiliaryLedgerDto> pageAccountingAuxiliaryDetailList(VAccountingSearchProgramme searchProgramme, Boolean isShowDetail, Boolean isDayBook) {
        return HttpResult.ok(auxiliaryLedgerService.pageAccountingAuxiliaryDetailList(searchProgramme, isShowDetail, isDayBook));
    }
}
